<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Introduction to Mono Winforms</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Winforms, Mono, C#, introduction, programming, tutorial">
<meta name="description" content="Introduction to Mono Winforms">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div class="content">


<a href="/" title="Home">Home</a>&nbsp;
<a href=".." title="Home">Contents</a>


<h1>Introduction to Mono Winforms</h1>


<p>
The first part of the Mono Winforms tutorial introduces the Mono platform 
and the Winforms library. 
</p>

<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* NewSquare */
google_ad_slot = "0364418177";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 

<h2>About this tutorial</h2>

<p>
This is Mono C# Winforms tutorial. Mono Winforms tutorial is for beginner programmers. 
The goal of this tutorial is to teach readers basics of GUI programming in Mono Winforms. 
The tutorial is created and tested on Linux. Nevertheless, it can be used on other 
operating systems as well. Most examples should run without modification. 
Images used in this tutorial can be downloaded <a href="/img/gui/sharpwinf/images.tgz">here</a>.
</p>


<h2>Mono</h2>

<p>
The Mono Project is an open development initiative sponsored by <b>Novell</b> 
to develop an open source, UNIX version of the Microsoft .NET development platform.
It is a .NET compatible set of tools, which include C# compiler, Common Language Runtime,
ADO.NET, ASP.NET and Winforms libraries. 
</p>

<p>
Mono can be divided into three groups:
</p>

<ul>
<li>Core components</li>
<li>Gnome development stack</li>
<li>Microsoft compatibility stack</li>
</ul>

<p>
The core components are the C# language and the Common language runtime. The Gnome development
stack includes the GTK# library and various database connectivity libraries. Finally the Microsoft
compatibility stack includes the ADO.NET, ASP.NET and the Winforms libraries. 
</p>

<p>
Mono is multiplatform programming platform. It can be run on Linux, BSD, 
Mac OS X, Solaris and Windows operating systems. It is a multilanguage effort. 
For now, only C# language is fully supported. Languages like Visual Basic or IronPython
are not yet finished. 
</p>

<h2>Winforms</h2>

<p>
Windows Forms is a graphical user interface application programming interface (API)
included as a part of Microsoft's .NET Framework.
As of 13 May 2008, Mono's System.Windows.Forms 2.0 is API complete. 
Simply put, Winforms is a library for creating GUI applications. 
</p>


<h2>Compiling examples</h2>

<p>
Our tutorial uses the C# language. To compile all the examples in this tutorial, we use the
<b>gmcs</b> compiler. The gmcs compiler implements the complete C# 2.0 specification 
including generics. C# source files must end with a .cs extension.
</p>

<pre>
$ gmcs --about
The Mono C# compiler is (C) 2001-2008, Novell, Inc.
The compiler source code is released under the terms of the GNU GPL
For more information on Mono, visit the project Web site
   http://www.mono-project.com
The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, 
Marek Safar, Raja R Harinath, Atushi Enomoto
</pre>

<p>
We have a simple C# source file. We will discuss the source later. For now, we concentrate
on the compilation process. 
</p>

<div class="codehead">simple.cs</div>
<pre class="code">
using System.Windows.Forms;
using System.Drawing;

public class Simple : Form
{
    public Simple()
    {
       Text = "Simple";
       Size = new Size(250, 200);
       CenterToScreen();
    }

    static public void Main()
    {
       Application.Run(new Simple());
    }
}
</pre>

<p>
C# applications use modules called assemblies. The Mono C# compiler by default only references 
three assemblies: mscorlib.dll, System.dll and System.Xml.dll. Any additional assembly must
be specified with a command line option of the compiler. In our simple example, we need
System.Windows.Forms.dll and System.Drawing.dll assemblies. 
</p>

<pre>
 gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll simple.cs
</pre>

<p>
Here we compile the simple.cs source file. If the output file name is not specified, 
we get the exe file with name equal to the source file name. In our example, simple.exe
file. 
</p>

<pre>
 gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll simple.cs -out:simpleexample.exe
</pre>

<p>
Here we specify the output file name. We compile source file and get simpleexample.exe file. 
</p>


<h2>Reference</h2>

<a href="http://www.mono-project.com">mono-project.com</a><br>
<a href="http://msdn.microsoft.com/en-us/library/bb966997.aspx">Winforms 2.0 on msdn.com</a><br>
<a href="http://java2s.com">java2s.com</a><br>
<a href="http://wikipedia.org">wikipedia.org</a><br>


<hr class="btm">

<p>
This was an introduction to the Mono Winforms library.
</p>



<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified December 18, 2008  <span class="copyright">&copy; 2007 - 2012 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>

